import java.io.IOException;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


public class Boom {
	public  int x, y;
	public  int w,h;
	public int direc;
	public static int xD, yD;
	public static int wD, hD;
	
	public int type;
	
	public int currFrame = 0;
	public int ROW = 5;
	
	public static boolean isdisappear = true;
	
	
	public static final int DAN = 0;
	public static final int FIRE = 1;
	
	public static int mstate ;
	public static int APPEAR = 0;
	public static int DISAPPEAR = 1;
	
	
	public static int DIREC_LEFT = 1;
	public static int DIREC_RIGHT = 2;
	

	Image img;
	
	public Boom(int x1, int y1, int t , int direc1){
		xD = x = x1;
		yD = y = y1;
		type = t;	
		direc = direc1;
		
		init(type);
		
		wD = w = img.getWidth();
		hD = h = img.getHeight()/ROW;
		mstate = APPEAR;
		isdisappear = false;
	}
	
	public void init(int type1)
	{
		try {
			switch (type1) {
			case DAN:
				img = Image.createImage("/dan.png");
				break;

			default:
				break;
			}						
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public void update()
	{		
		
		moveFire();		
		setRemoveBoom();
		
	}
	
	public void setRemoveBoom()
	{
		if(mstate == DISAPPEAR)
		{
			Cuop.vecboom.removeElement(this);
		}
	}
	
	int xx ;
	public void moveFire()
	{
		
		if(direc == 1)
		{
			xx  = -10;
		}
		else if(direc == 2)
		{
			xx = 10;
		}
		
		x += xx;
		xD = x;
	
		currFrame = ++currFrame % ROW;
		
		if(xD <Cuop.cmX - w || xD > Cuop.cmX+ Mscreen.widthScreen - 5)
		{
			xD+=0;			
			mstate = DISAPPEAR;
			isdisappear = true;
		}
	}
	

	
	public void paint(Graphics g)
	{
		switch (type) {
		case DAN:
			g.drawRegion(img, 0, hD*currFrame, wD, hD, 0, xD, yD, Graphics.VCENTER|Graphics.HCENTER);
			break;

		default:
			break;
		}
		
	}
}
